﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;

namespace QuaManSys
{
    public class CommonFunctions
    {
        /// <summary>
        /// 查询状态为分发的内部质量信息条数
        /// </summary>
        /// <returns></returns>
        public static int QueryInnerStatusDis()
        {
            using (QuaManSysEntities context = new QuaManSysEntities())
            {
                var inInfoDis =
                    from c in context.InnerQualityInfo
                    where c.processingStatus == "分发"
                    select c;
                int disNumber = inInfoDis.Count();
                return disNumber;
            }
        }

        /// <summary>
        /// 查询状态为处理的内部质量信息条数
        /// </summary>
        /// <returns></returns>
        public static int QueryInnerStatusPro(string department)
        {
            using (QuaManSysEntities context = new QuaManSysEntities())
            {
                if ("QA" == department)
                {
                    var inInfoPro =
                    from c in context.InnerQualityInfo
                    where c.processingStatus == "处理"
                    select c;
                    int fileNumer = inInfoPro.Count();
                    return fileNumer;
                }
                else
                {
                    var inInfoPro =
                    from c in context.InnerQualityInfo
                    join o in context.InnerResponsibleDepart on c.qualityInfoId equals o.qualityInfoId
                    where c.processingStatus == "处理" &&  department == o.department
                    select c;
                    int fileNumer = inInfoPro.Distinct().Count();
                    return fileNumer;
                }
            }
        }

        /// <summary>
        /// 查询"状态为处理"责任部门为department的内部质量信息条数
        /// </summary>
        /// <param name="repdepartment"></param>
        /// <returns></returns>
        public static int QueryInnerResStatusPro(string repdepartment)
        {
            using (QuaManSysEntities context = new QuaManSysEntities())
            {
                var inInfoResStatusPro =
                from c in context.InnerQualityInfo
                join o in context.InnerResponsibleDepart on c.qualityInfoId equals o.qualityInfoId
                where c.processingStatus == "处理" &&  repdepartment == o.department
                    && o.isResponDepart == 1
                select c;
                int fileNumer = inInfoResStatusPro.Distinct().Count();
                return fileNumer;
            }
        }

        /// <summary>
        /// 查询状态为归档的内部质量信息条数
        /// </summary>
        /// <returns></returns>
        public static int QueryInnerStatusFile()
        {
            using (QuaManSysEntities context = new QuaManSysEntities())
            {
                var inInfoFile =
                    from c in context.InnerQualityInfo
                    where c.processingStatus == "归档"
                    select c;
                int fileNumer = inInfoFile.Count();
                return fileNumer;
            }
        }

        /// <summary>
        /// 查询状态为分发的外部质量信息条数
        /// </summary>
        /// <returns></returns>
        public static int QueryOuterStatusDis()
        {
            using (QuaManSysEntities context = new QuaManSysEntities())
            {
                var outInfoFile =
                    from c in context.OuterQualityInfo
                    where c.processingStatus == "分发"
                    select c;
                int fileNumer = outInfoFile.Count();
                return fileNumer;
            }
        }

        /// <summary>
        /// 查询状态为处理的外部质量信息条数
        /// </summary>
        /// <returns></returns>
        public static int QueryOuterStatusPro(string department)
        {
            using (QuaManSysEntities context = new QuaManSysEntities())
            {
                if ("QA" == department)
                {
                    var outInfoPro =
                    from c in context.OuterQualityInfo
                    where c.processingStatus == "处理"
                    select c;
                    int fileNumer = outInfoPro.Count();
                    return fileNumer;
                }
                else
                {
                    var outInfoPro =
                    from c in context.OuterQualityInfo
                    join o in context.OuterResponsibleDepart on c.qualityInfoId equals o.qualityInfoId
                    where c.processingStatus == "处理" && department == o.department
                    select c;
                    int fileNumer = outInfoPro.Distinct().Count();
                    return fileNumer;
                }
            }
        }

        /// <summary>
        /// 查询"状态为处理"责任部门为department的内部质量信息条数
        /// </summary>
        /// <param name="repdepartment"></param>
        /// <returns></returns>
        public static int QueryOuterResStatusPro(string repdepartment)
        {
            using (QuaManSysEntities context = new QuaManSysEntities())
            {
                var outInfoResStatusPro =
                from c in context.OuterQualityInfo
                join o in context.OuterResponsibleDepart on c.qualityInfoId equals o.qualityInfoId
                where c.processingStatus == "处理" && repdepartment == o.department
                    && o.isResponDepart == 1
                select c;
                int fileNumer = outInfoResStatusPro.Distinct().Count();
                return fileNumer;
            }
        }

        /// <summary>
        /// 查询状态为归档的外部质量信息条数
        /// </summary>
        /// <returns></returns>
        public static int QueryOuterStatusFile()
        {
            using (QuaManSysEntities context = new QuaManSysEntities())
            {
                var outInfoFile =
                    from c in context.OuterQualityInfo
                    where c.processingStatus == "归档"
                    select c;
                int fileNumer = outInfoFile.Count();
                return fileNumer;
            }
        }
    }
}